from tkinter import *
import tkinter.messagebox
from login import *
from plane_description import *
from snake_description import *
from game2048_description import *
from textarea import *

# class MianPageClass(self,root,s,name):
#     self.root = root
#     self.s = s
#     self.name = name

def mainpage(root,s,name):
    # 创建应用程序窗口
    root.withdraw()
    root2 = Toplevel()
        # 创建标题
    root2.title("欢迎来到娱乐世界")
    varName = StringVar()
    varName.set('')
    varPwd = StringVar()
    varPwd.set('')
        # 设置窗口大小
    convas = tkinter.Canvas(root2, height=500, width=500, bg="#BBB990")
    root2.geometry('500x500+300+150')


    photo = tkinter.PhotoImage(file="image/main.png")  # file：t图片路径
    imgLabel = tkinter.Label(root2,image=photo, compound=tkinter.CENTER)  # 把图片整合到标签类中
    imgLabel.pack(side=tkinter.LEFT)  # 自动对齐
    imgLabel.place(x=0, y=0)

    UserName = tkinter.Label(root2, text=name+", 欢迎光临游戏世界！", width=80, font=("微软雅黑", 20))
    UserName.place(x=75, y=50, width=350, height=50)

    def byebye(s,name):
        s.send(b'E')
        print(name+", 谢谢您的使用,您已退出该系统！")
        s.close()

    def cancel():
        byebye(s,name)
        root.destroy()

    def plane_open():
        plane_description(root2,s,name)

    def snake_open():
        snake_description(root2,s,name)

    def game2048_open():
        game2018_description(root2,s,name)

    def movie_game_open():
        movie_game_description(root2,s)

    convas.pack()
    button1 = Button(root2, text='飞机大战', bg="#C4BDAD",font=("微软雅黑", 12),command=plane_open)
    button1.place(x=105, y=250, width=120, height=45)

    button2 = Button(root2, text='蛇', bg="#C4BDAD",font=("微软雅黑", 12),command=snake_open)
    button2.place(x=270, y=250, width=120, height=45)

    button4 = Button(root2, text='2048', bg="#C4BDAD",font=("微软雅黑", 12),command=game2048_open)
    button4.place(x=105, y=330, width=120, height=45)

    button5 = Button(root2, text="最火游戏与电影", bg="#C4BDAD",font=("微软雅黑", 12),command=movie_game_open)
    button5.place(x=270, y=330, width=120, height=45)

    button6 = Button(root2, text='退出', bg="#C4BDAD",font=("微软雅黑", 12),command=cancel)
    button6.place(x=180, y=405, width=120, height=45)

        # 启动消息循环
    root2.mainloop()